package com.pig4cloud.pig.demo.Config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class MyMetaObjectHandle implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        //user实体类
        this.strictInsertFill(metaObject, "createdTime", Date.class, new Date());
        this.strictInsertFill(metaObject, "updatedTime", Date.class, new Date());
        this.strictInsertFill(metaObject, "updatePwdtime", Date.class, new Date());

        //article实体类
        this.strictInsertFill(metaObject, "publishTime", Date.class, new Date());
        this.strictInsertFill(metaObject, "updateTime", Date.class, new Date());

        //comment实体类
        this.strictInsertFill(metaObject, "published", Date.class, new Date());


    }

    @Override
    public void updateFill(MetaObject metaObject) {
        //user实体类
        this.strictUpdateFill(metaObject, "updatedTime", Date.class, new Date());

        //article实体类
        this.strictUpdateFill(metaObject, "updateTime", Date.class, new Date());
    }
}
